<template>
  <div>
    <el-tree
  :data="data"
  node-key="id"
  @node-click="handleNodeClick"
  :props="defaultProps">
</el-tree>
  </div>
</template>

<script>
import { listCamera} from "@/api/resource/equipment/camera/camera";
import axios from 'axios'

export default {
  // props:{
  //   treeList: {type:Object},
  //   required: true
  // },
data() {
      return {
        // data: [{
        //   id: 1,
        //   label: '东北大学浑南校区',
        //   children: [{
        //     id: 2,
        //     label: '华为测试01',
        //     cameraId: 1
        //   }, {
        //     id: 6,
        //     label: '二级 2-2'
        //   }]
        // }],
         // 摄像机表格数据
        cameraList: [],
        data: [{
          id: 0,
          label: '东北大学浑南校区',
          children: [{
            id: 1,
            label: '华为测试1',
          }]
        }],
        defaultProps: {
          children: 'children',
          label: 'label'
        }
      };
    },
    created() {
        
    },
    mounted(){
 
      listCamera(this.queryParams).then(response => {
        console.log("开始查询摄像机列表",response)
        this.cameraList = response.rows;
        // this.data[0].children = this.cameraList
        console.log(this.cameraList)
      });
    },
    // mounted() {
    //   // treeList.array.forEach(m => {
    //   //   dataList.push({id:m.id,label:m.camera_name})
    //   // });
    //   console.log("开始打印treelist")
    //   console.log(this.treeList)
    // },
    // watch: {
    //   treeList:{
    //     handler(newVal,oldVal){
    //       immediate: true, //绑定值就开始执行监听，而不是等值改变。
    //       console.log("开始打印treelist")
    //       console.log(newVal)
    //       this.dataList = []
    //       this.dataList.push({id:newVal.value.id,label:newVal.value.cameraName})
          
    //       console.log("开始打印dataList")
    //       console.log(this.dataList)
    //     }
    //   }
    // },
    methods: {
      handleNodeClick(data1) {
        console.log(data1);
        if(data1.id !== 0){
          this.$store.commit('setCamera',data1.id)
          axios.get("http://localhost:8080/rtsp/test/1/'0'").then(function(res){
    console.log(res);
     })
     .catch(function(err){
    console.log(err);
})
        }
      }
    }
  };
</script>

<style>